home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
c
/
dice-3.16.lha
/
doc
/
stdio.doc
< prev
next >
Wrap
Text File
|
1993-07-06
|
57KB
|
2,454 lines
STDIO.DOC (c)Copyright 1990, Matthew Dillon, All Rights Reserved
TABLE OF CONTENTS
c.lib/stdio/clearerr
c.lib/stdio/fclose
c.lib/stdio/fdopen
c.lib/stdio/feof
c.lib/stdio/ferror
c.lib/stdio/fflush
c.lib/stdio/fgetc
c.lib/stdio/fgetpos
c.lib/stdio/fgets
c.lib/stdio/filbuf
c.lib/stdio/fileno
c.lib/stdio/fopen
c.lib/stdio/fprintf
c.lib/stdio/fputc
c.lib/stdio/fputs
c.lib/stdio/fread
c.lib/stdio/freopen
c.lib/stdio/fscanf
c.lib/stdio/fseek
c.lib/stdio/fsetpos
c.lib/stdio/ftell
c.lib/stdio/fwrite
c.lib/stdio/getc
c.lib/stdio/getchar
c.lib/stdio/gets
c.lib/stdio/perror
c.lib/stdio/pfmt
c.lib/stdio/printf
c.lib/stdio/putc
c.lib/stdio/putchar
c.lib/stdio/puts
c.lib/stdio/remove
c.lib/stdio/rename
c.lib/stdio/rewind
c.lib/stdio/scanf
c.lib/stdio/setbuf
c.lib/stdio/setvbuf
c.lib/stdio/sprintf
c.lib/stdio/sscanf
c.lib/stdio/stdin
c.lib/stdio/stdout
c.lib/stdio/stderr
c.lib/stdio/tmpfile
c.lib/stdio/tmpnam
c.lib/stdio/ungetc
c.lib/stdio/vfprintf
c.lib/stdio/vprintf
c.lib/stdio/vsprintf
stdio/file_pointer stdio/file_pointer
A file pointer is the basis for STDIO, a standard file buffering
package across all versions of C.
The specific Amiga implementation uses file descriptors (see
the file_descriptor manual page) as its interface to the
filesystem.
Remember that a stdio file pointer is NOT a file descriptor nor
an AmigaDOS file handle. You may call only stdio routines (fopen,
fclose, fread, fwrite, etc...) with file pointers.
Some C implementations flush stdout whenever stdin is read. DICE
does not do this.
stdio/clearerr stdio/clearerr
NAME
clearerr - clear error associated with a file pointer
SYNOPSIS
#include <stdio.h>
void clearerr(fp); (MACRO)
FILE *fp;
FUNCTION
The clearerr() macro clears both the EOF flag and the ERROR
flag associated with a file pointer. When an ERROR occurs on
a file pointer further fread, fwrite, and some other calls will
not work (i.e. fail) until the ERROR indicator is cleared.
NOTE
refer to the file_pointer manual page for general information
INPUTS
FILE *fp; file pointer to clear the error on.
RESULTS
none, the error and EOF indicators are cleared
SEE ALSO
feof, ferror, rewind, fseek
stdio/fclose stdio/fclose
NAME
fclose - close a file pointer
SYNOPSIS
#include <stdio.h>
int error = fclose(fp);
FILE *fp;
FUNCTION
fclose flushes any data remaining in the file pointer's
output buffer to the file and then closes the file. The
file pointer is no longer valid.
fclose returns any error condition that occured while flushing
the buffered data to the file. The file is still closed even
if an error occurs.
NOTE
You can fclose(stdin), fclose(stdout), and fclose(stderr) as
you wish to save space and/or detach your process from the
console (i.e. allow the console window to be closed).
WARNING
If you fclose stdin, stdout, and stderr with the intension of
removing all references to the console window there is still
one more thing you have to do, and that is put a NULL in
your processes pr_ConsoleTask field. Otherwise, while the
console window will be able to close, your process will still
have a reference to the now non existant window if it attempts
to spawn or Execute() other processes.
refer to the file_pointer manual page for general information
INPUTS
FILE *fp; file pointer
RESULTS
int error; error on fclose, or 0 if none
SEE ALSO
fopen, fread, fwrite, fgets, fputs
stdio/fdopen stdio/fdopen
NAME
fdopen - associate a file pointer with an already open file
descriptor
SYNOPSIS
#include <stdio.h>
FILE *fp = fdopen(fd, modes);
int fd;
char *modes;
FUNCTION
fdopen associates an already open file descriptor with a file
pointer. Note that fclose()ing the file pointer will also
close() the file descriptor.
Refer to the fopen manual page for a description of available
modes. Note that when you use fdopen the file will not be
truncated and if you specify mode 'a' for append, the file
descriptor MUST have been open()'d with the O_APPEND flag.
That is, the mode string should be similar to the open flags
that were used to open the file descriptor.
NOTE
refer to the file_pointer manual page for general information
INPUTS
int fd; file descriptor to associated with a new file pointer
char *modes; modes string, such as "r+".
RESULTS
FILE *fp; new file pointer or NULL if an error occured
SEE ALSO
fopen, fread, fwrite, fgets, fputs
stdio/feof stdio/feof
NAME
feof - return EOF condition for file pointer
SYNOPSIS
#include <stdio.h>
int r = feof(fp); (MACRO)
FILE *fp;
FUNCTION
feof returns the EOF status of a file pointer. The status is
not changed by this macro. 0 is returned if no EOF condition
exists, non-zero if an EOF condition exists (NOT necessarily
1 or -1, just non-zero).
use clearerr() to clear the EOF condition. Also, fseek() and
rewind() also clear an EOF condition.
NOTE
refer to the file_pointer manual page for general information
INPUTS
FILE *fp; file pointer
RESULTS
int r; 0 if no EOF condition exists, != 0 if an EOF
condition exists (not necessarily 1 or -1).
SEE ALSO
fopen, fclose, fread, fwrite, fgets, fputs
stdio/ferror stdio/ferror
NAME
ferror - return ERROR condition for file pointer
SYNOPSIS
#include <stdio.h>
int r = ferror(fp); (MACRO)
FILE *fp;
FUNCTION
ferror returns the ERROR status of a file pointer. The status is
not changed by this macro. 0 is returned if no ERROR condition
exists, non-zero if an ERROR condition exists (NOT necessarily 1 or
-1, just non-zero).
NOTE
refer to the file_pointer manual page for general information
INPUTS
FILE *fp; file pointer
RESULTS
int r; 0 if no ERROR condition exists, != 0 if an ERROR
condition exists (not necessarily 1 or -1).
SEE ALSO
fopen, fclose, fread, fwrite, fgets, fputs
stdio/fflush stdio/fflush
NAME
fflush - flush buffers to file
SYNOPSIS
#include <stdio.h>
int error = fflush(fp);
FILE *fp;
FUNCTION
fflush writes out any buffered data out to the file descriptor
associated with the file pointer.
Normally a file is either unbuffered, line buffered, or fully
buffered. fflush is useful in the later two cases as is shown
by the example.
fflush will return -1 if a write error occured, 0 if no error
occured.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* Since text to stdout is normally line buffered, if we do not
* write out a newline '\n' then the line is still buffered in
* memory and we have to fflush() to write it out.
*/
#include <stdio.h>
main()
{
char buf[256];
printf("Enter a number -");
fflush(stdout);
gets(buf);
printf("Munch Munch...");
fflush(stdout);
sleep(1);
puts("Thanks!");
}
INPUTS
FILE *fp; file pointer
RESULTS
int error; 0 if no error, -1 on error.
SEE ALSO
fopen, fclose, fread, fwrite, fgets, fputs
stdio/fgetc stdio/fgetc
stdio/getc stdio/getc
NAME
fgetc - get a single character from a file pointer
getc - get a single character from a file pointer (MACRO)
SYNOPSIS
#include <stdio.h>
int c = fgetc(fp);
int c = getc(fp); (MACRO)
FILE *fp;
FUNCTION
[f]getc() reads a single character from a file pointer. The value
returned is actually an int because EOF (-1) must be differentiated
from a 255.
[f]getc() returns an integer 0-255 or EOF (-1) if an end of file
occurs.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* copy stdin to stdout using getc/putc. Normally one uses
* fread/fwrite, but I'll save that for the fread manual page.
*
* note that I output the initial message to stderr so it does
* not get stuck into stdout in case the user has redirected
* stdout.
*/
#include <stdio.h>
main()
{
int c;
fputs("Type a couple of lines, then ^\ (EOF)\n", stderr);
while ((c = getc(stdin)) != E